<?php

//vendor 助手函数
function vendor($class)
{
	$class_dir = VENDOR_PATH . $class;
	
	return include($class_dir);
}

//json
function ajaxReturn($res)
{
    return json_encode($res);
}

//下载文件
function downPic($url,$path = '/')
{
	$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);

    $file = curl_exec($ch);

    curl_close($ch);

    $res = saveAsImage($url, $file, $path);
	
	return $res;
}

//保存到本地
function saveAsImage($url, $file, $path)
{
    $filename = pathinfo($url, PATHINFO_BASENAME);

    $resource = fopen($path .'/'. $filename, 'a');

    fwrite($resource, $file);

    fclose($resource);
	
	return $filename;
}

//补零
function paddZero($val){
    if ($val < 10) {
        return ("0" . $val);
    }else {
        return ($val);
    }
}